package com.zhangyu.shadow.repair.delegate.search;

import android.content.Context;

import com.zhangyu.shadow.repair.R;
import com.zhangyu.shadow.repair.config.RepairItemType;
import com.zhangyu.shadow.repair.config.SpKey;
import com.zhangyu.shadow.repair.config.StateCode;
import com.zhangyu.shadow.repair.delegate.search.entity.MaintainEntity;

import java.util.List;

import st.lib.base.storage.ShadowPreference;
import st.lib.base.ui.recycler.MultipleItemEntity;
import st.lib.base.ui.recycler.MultipleRecyclerAdapter;
import st.lib.base.ui.recycler.MultipleViewHolder;

import static com.zhangyu.shadow.repair.config.RepairItemType.ITEM_TYPE_MAINTAIN;

/**
 * @author zhangyu
 * @date 2018/2/13
 */

public class SearchDataAdapter extends MultipleRecyclerAdapter {
    private int mColorBlack;
    private int mColorGreen;
    private int mColorYellow;

    public SearchDataAdapter(Context context, List<MultipleItemEntity> data) {
        super(data);
        mColorBlack = context.getResources().getColor(R.color.color_white_gray);
        mColorGreen = context.getResources().getColor(R.color.color_green);
        mColorYellow = context.getResources().getColor(R.color.color_yellow);
        addItemType(RepairItemType.ITEM_TYPE_REPAIR, R.layout.item_search_bus_repair);
        addItemType(RepairItemType.ITEM_TYPE_MAINTAIN, R.layout.item_search_bus_maintain);
    }

    @Override
    protected void convert(MultipleViewHolder helper, MultipleItemEntity item) {
        if (item.getItemType() == RepairItemType.ITEM_TYPE_REPAIR) {
            MaintainEntity repairEntity = item.getField(RepairItemType.ITEM_REPAIR);
            helper.setText(R.id.tv_bus_number, repairEntity.getVehicleCode());
            helper.setText(R.id.tv_bus_line, repairEntity.getRouteName());
            //TODO 根据车辆状态判断
            String info = "修理厂:" + ShadowPreference.getCustomAppProfile(SpKey.FACTORY_NAME);
            int color = mColorBlack;
            String state = "未报修";
            switch (repairEntity.getWorkStatusCode()) {
                case StateCode.FINISH_PLAN:
                    info = "修理厂:" + ShadowPreference.getCustomAppProfile(SpKey.FACTORY_NAME);
                    color = mColorBlack;
                    state = "未报修";
                    break;
                case StateCode.READY_WORK:
                    info = "报修时间:" + repairEntity.getTroubleTime();
                    color = mColorYellow;
                    state = "已报修";
                    break;
                case StateCode.UNDER_WORK:
                    info = "报修时间:" + repairEntity.getTroubleTime();
                    color = mColorYellow;
                    state = "修理中";
                    break;
                case StateCode.COMPLETED_WORK:
                    info = "报修时间:" + repairEntity.getTroubleTime();
                    color = mColorYellow;
                    state = "已竣检";
                    break;
                case StateCode.FINISH_WORK:
                    info = "报修时间:" + repairEntity.getTroubleTime();
                    color = mColorGreen;
                    state = "已交车";
                    break;
                default:

                    break;
            }
            helper.setTextColor(R.id.tv_bus_icon, color);
            helper.setText(R.id.tv_bus_info, info);
            helper.setTextColor(R.id.tv_bus_state, color);
            helper.setText(R.id.tv_bus_state, state);

        } else if (item.getItemType() == ITEM_TYPE_MAINTAIN) {
            MaintainEntity maintainEntity = item.getField(RepairItemType.ITEM_MAINTAIN);
            helper.setText(R.id.tv_bus_number, maintainEntity.getVehicleCode());
            helper.setText(R.id.tv_bus_line, maintainEntity.getRouteName());
            helper.setText(R.id.tv_maintain_level, maintainEntity.getMaintenanceTypeName());
            helper.setText(R.id.tv_bus_info, "计划保养时间:" + maintainEntity.getPlanStartTime());
            int color = mColorBlack;
            String state = "未报修";
            switch (maintainEntity.getWorkStatusCode()) {
                case StateCode.FINISH_PLAN:
                    color = mColorBlack;
                    state = "未报修";
                    break;
                case StateCode.READY_WORK:
                    color = mColorYellow;
                    state = "已报修";
                    break;
                case StateCode.UNDER_WORK:
                    color = mColorYellow;
                    state = "修理中";
                    break;
                case StateCode.COMPLETED_WORK:
                    color = mColorYellow;
                    state = "已竣检";
                    break;
                case StateCode.FINISH_WORK:
                    color = mColorGreen;
                    state = "已交车";
                    break;
                default:

                    break;
            }
            helper.setTextColor(R.id.tv_bus_icon, color);
            helper.setTextColor(R.id.tv_bus_state, color);
            helper.setText(R.id.tv_bus_state, state);
        }
    }
}
